#include<string>
#include"MainHeader.h"

/*
class Security
{
public:
	int CheckPasswordReal(string &IntPutPassword, string &IntPutUserNAme);//返回0时正确，返回1时账户名错误，返回2时密码错误，返回3异常错误
	string UserNameAdmin = "GSMAdmin";
	string PasswordAdmin = "Caiji1281";
};

Security ServerMain;

int Security::CheckPasswordReal(string &IntPutPassword, string &IntPutUserNAme)
{
	if (IntPutPassword == UserNameAdmin)
	{
		if ( IntPutPassword == PasswordAdmin)
		{
			return 0;
		}
		else
		{
			return 2;
		}
	}
	else
	{
		return 1;
	}
	return 3;
}


int ModuleUserLogIn()
{
	cout << "请输入服务器GSM账号:" << endl;
	string UserInputUserName, UserInputUserPassword;
	cin >> UserInputUserName;
	cout << "\n请输入服务器GSM密码:" << endl;
	cin >> UserInputUserPassword;
	int IntputSat = ServerMain.CheckPasswordReal(UserInputUserPassword, UserInputUserName);
	bool LogInSucc;
	switch (IntputSat)//返回0时正确，返回1时账户名错误，返回2时密码错误，返回3异常错误
	{
	case 0: LogInSucc = true;
		break;
	case 1:cout << "您输入信息有误错误代号1 \n 程序即将退出" << endl;
		exit(21);
		break;
	case 2:cout << "您输入信息有误错误代号2 \n 程序即将退出" << endl;
		exit(22);
		break;
	default:cout << "程序错误，退出" << endl;
		exit(666);
		break;
	}
	MoudleSecurityMain(LogInSucc);
}
*/

/*先废弃掉密码模块，优化完了再说...*/

int MoudleSecurityMain()
{
	cout << "欢迎管理员进入GSM设置 \n A:开启防火墙          B:关闭防火墙          C:紧急情况          D:一键删库          Q:退出模块\n" << endl;
	cout << "请输入您的选项:" << endl;
	char temp; 
	cin >> temp;
	while (temp != 'Q')
	{
		switch (temp)
		{
		case 'A':FireWallSet(true);
			break;
		case 'B':FireWallSet(false);
			break;
		case 'C':Emergency();
			break;
		case 'D':DelDataBase();
			break;
		case 'Q':
			return 0;
			break;
		default:cout << "请输入正确的选项\n" << endl;
			break;
		}
		cout << "欢迎管理员进入GSM设置 \n A:开启防火墙          B:关闭防火墙          C:紧急情况          D:一键删库          Q:退出模块\n" << endl;
		cout << "请输入您的选项:" << endl;
		cin >> temp;
	}

}


int FireWallSet(bool IsOpen)//关闭为否，打开为是
{
	/*上行出站，下行进站*/
	/*
	墓前防火墙规则：
	Classical：32443，32102
	Origin：36000 36102
	OriginGan：36100，36101
	*/
	/*开始清空防火墙规则*/
	cout << "开始清空先前的防火墙规则，请稍后..." << endl;
	/*清空上行允许TCP规则*/
	system("netsh advfirewall firewall delete rule name=ClassicalDispath上行TCP dir=out protocol=tcp localport=32443");
	system("netsh advfirewall firewall delete rule name=ClassicalGame上行TCP dir=out protocol=tcp localport=32102");
	system("netsh advfirewall firewall delete rule name=OriginDispath上行TCP dir=out protocol=tcp localport=36000");
	system("netsh advfirewall firewall delete rule name=OriginGame上行TCP dir=out protocol=tcp localport=36102");
	system("netsh advfirewall firewall delete rule name=OriginGanDispath上行TCP dir=out protocol=tcp localport=36100");
	system("netsh advfirewall firewall delete rule name=OriginGanGame上行TCP dir=out protocol=tcp localport=36101");
	/*清空上行允许UDP规则*/
	system("netsh advfirewall firewall delete rule name=ClassicalDispath上行UDP dir=out protocol=udp localport=32443");
	system("netsh advfirewall firewall delete rule name=ClassicalGame上行UDP dir=out protocol=udp localport=32102");
	system("netsh advfirewall firewall delete rule name=OriginDispath上行UDP dir=out protocol=udp localport=36000");
	system("netsh advfirewall firewall delete rule name=OriginGame上行UDP dir=out protocol=udp localport=36102");
	system("netsh advfirewall firewall delete rule name=OriginGanDispath上行UDP dir=out protocol=udp localport=36100");
	system("netsh advfirewall firewall delete rule name=OriginGanGame上行UDP dir=out protocol=udp localport=36101");
	/*清空下行允许TCP规则*/
	system("netsh advfirewall firewall delete rule name=ClassicalDispath上行TCP dir=in protocol=tcp localport=32443");
	system("netsh advfirewall firewall delete rule name=ClassicalGame上行TCP dir=in protocol=tcp localport=32102");
	system("netsh advfirewall firewall delete rule name=OriginDispath上行TCP dir=in protocol=tcp localport=36000");
	system("netsh advfirewall firewall delete rule name=OriginGame上行TCP dir=in protocol=tcp localport=36102");
	system("netsh advfirewall firewall delete rule name=OriginGanDispath上行TCP dir=in protocol=tcp localport=36100");
	system("netsh advfirewall firewall delete rule name=OriginGanGame上行TCP dir=in protocol=tcp localport=36101");
	/*清空下行允许UDP规则*/
	system("netsh advfirewall firewall delete rule name=ClassicalDispath上行UDP dir=in protocol=udp localport=32443");
	system("netsh advfirewall firewall delete rule name=ClassicalGame上行UDP dir=in protocol=udp localport=32102");
	system("netsh advfirewall firewall delete rule name=OriginDispath上行UDP dir=in protocol=udp localport=36000");
	system("netsh advfirewall firewall delete rule name=OriginGame上行UDP dir=in protocol=udp localport=36102");
	system("netsh advfirewall firewall delete rule name=OriginGanDispath上行UDP dir=in protocol=udp localport=36100");
	system("netsh advfirewall firewall delete rule name=OriginGanGame上行UDP dir=in protocol=udp localport=36101");
	/*清空上行禁止TCP规则*/
	system("netsh advfirewall firewall delete rule name=ClassicalDispath上行TCP dir=out protocol=tcp localport=32443");
	system("netsh advfirewall firewall delete rule name=ClassicalGame上行TCP dir=out protocol=tcp localport=32102");
	system("netsh advfirewall firewall delete rule name=OriginDispath上行TCP dir=out protocol=tcp localport=36000");
	system("netsh advfirewall firewall delete rule name=OriginGame上行TCP dir=out protocol=tcp localport=36102");
	system("netsh advfirewall firewall delete rule name=OriginGanDispath上行TCP dir=out protocol=tcp localport=36100");
	system("netsh advfirewall firewall delete rule name=OriginGanGame上行TCP dir=out protocol=tcp localport=36101");
	/*清空上行禁止UDP规则*/
	system("netsh advfirewall firewall delete rule name=ClassicalDispath上行UDP dir=out protocol=udp localport=32443");
	system("netsh advfirewall firewall delete rule name=ClassicalGame上行UDP dir=out protocol=udp localport=32102");
	system("netsh advfirewall firewall delete rule name=OriginDispath上行UDP dir=out protocol=udp localport=36000");
	system("netsh advfirewall firewall delete rule name=OriginGame上行UDP dir=out protocol=udp localport=36102");
	system("netsh advfirewall firewall delete rule name=OriginGanDispath上行UDP dir=out protocol=udp localport=36100");
	system("netsh advfirewall firewall delete rule name=OriginGanGame上行UDP dir=out protocol=udp localport=36101");
	/*清空下行禁止TCP规则*/
	system("netsh advfirewall firewall delete rule name=ClassicalDispath上行TCP dir=in protocol=tcp localport=32443");
	system("netsh advfirewall firewall delete rule name=ClassicalGame上行TCP dir=in protocol=tcp localport=32102");
	system("netsh advfirewall firewall delete rule name=OriginDispath上行TCP dir=in protocol=tcp localport=36000");
	system("netsh advfirewall firewall delete rule name=OriginGame上行TCP dir=in protocol=tcp localport=36102");
	system("netsh advfirewall firewall delete rule name=OriginGanDispath上行TCP dir=in protocol=tcp localport=36100");
	system("netsh advfirewall firewall delete rule name=OriginGanGame上行TCP dir=in protocol=tcp localport=36101");
	/*清空下行禁止UDP规则*/
	system("netsh advfirewall firewall delete rule name=ClassicalDispath上行UDP dir=in protocol=udp localport=32443");
	system("netsh advfirewall firewall delete rule name=ClassicalGame上行UDP dir=in protocol=udp localport=32102");
	system("netsh advfirewall firewall delete rule name=OriginDispath上行UDP dir=in protocol=udp localport=36000");
	system("netsh advfirewall firewall delete rule name=OriginGame上行UDP dir=in protocol=udp localport=36102");
	system("netsh advfirewall firewall delete rule name=OriginGanDispath上行UDP dir=in protocol=udp localport=36100");
	system("netsh advfirewall firewall delete rule name=OriginGanGame上行UDP dir=in protocol=udp localport=36101");
	cout << "清空完毕!!!\n开始执行操作" << endl;
	switch (IsOpen)
	{
	case true:
		cout << "操作:开放端口\n执行中..." << endl;
		/*添加上行TCP规则*/
		system("netsh advfirewall firewall add rule name=ClassicalDispath上行TCP dir=out action=allow protocol=tcp localport=32443");
		system("netsh advfirewall firewall add rule name=ClassicalGame上行TCP dir=out action=allow protocol=tcp localport=32102");
		system("netsh advfirewall firewall add rule name=OriginDispath上行TCP dir=out action=allow protocol=tcp localport=36000");
		system("netsh advfirewall firewall add rule name=OriginGame上行TCP dir=out action=allow protocol=tcp localport=36102");
		system("netsh advfirewall firewall add rule name=OriginGanDispath上行TCP dir=out action=allow protocol=tcp localport=36100");
		system("netsh advfirewall firewall add rule name=OriginGanGame上行TCP dir=out action=allow protocol=tcp localport=36101");
		/*添加上行UDP规则*/
		system("netsh advfirewall firewall add rule name=ClassicalDispath上行UDP dir=out action=allow protocol=udp localport=32443");
		system("netsh advfirewall firewall add rule name=ClassicalGame上行UDP dir=out action=allow protocol=udp localport=32102");
		system("netsh advfirewall firewall add rule name=OriginDispath上行UDP dir=out action=allow protocol=udp localport=36000");
		system("netsh advfirewall firewall add rule name=OriginGame上行UDP dir=out action=allow protocol=udp localport=36102");
		system("netsh advfirewall firewall add rule name=OriginGanDispath上行UDP dir=out action=allow protocol=udp localport=36100");
		system("netsh advfirewall firewall add rule name=OriginGanGame上行UDP dir=out action=allow protocol=udp localport=36101");
		/*添加下行TCP规则*/
		system("netsh advfirewall firewall add rule name=ClassicalDispath上行TCP dir=in action=allow protocol=tcp localport=32443");
		system("netsh advfirewall firewall add rule name=ClassicalGame上行TCP dir=in action=allow protocol=tcp localport=32102");
		system("netsh advfirewall firewall add rule name=OriginDispath上行TCP dir=in action=allow protocol=tcp localport=36000");
		system("netsh advfirewall firewall add rule name=OriginGame上行TCP dir=in action=allow protocol=tcp localport=36102");
		system("netsh advfirewall firewall add rule name=OriginGanDispath上行TCP dir=in action=allow protocol=tcp localport=36100");
		system("netsh advfirewall firewall add rule name=OriginGanGame上行TCP dir=in action=allow protocol=tcp localport=36101");
		/*添加下行UDP规则*/
		system("netsh advfirewall firewall add rule name=ClassicalDispath上行UDP dir=in action=allow protocol=udp localport=32443");
		system("netsh advfirewall firewall add rule name=ClassicalGame上行UDP dir=in action=allow protocol=udp localport=32102");
		system("netsh advfirewall firewall add rule name=OriginDispath上行UDP dir=in action=allow protocol=udp localport=36000");
		system("netsh advfirewall firewall add rule name=OriginGame上行UDP dir=in action=allow protocol=udp localport=36102");
		system("netsh advfirewall firewall add rule name=OriginGanDispath上行UDP dir=in action=allow protocol=udp localport=36100");
		system("netsh advfirewall firewall add rule name=OriginGanGame上行UDP dir=in action=allow protocol=udp localport=36101");
		cout << "防火墙规则开放完毕，" << endl;
		break;
	case false:
		cout << "操作:关闭端口\n执行中..." << endl;
		/*添加上行TCP规则*/
		system("netsh advfirewall firewall add rule name=ClassicalDispath上行TCP dir=out action=block protocol=tcp localport=32443");
		system("netsh advfirewall firewall add rule name=ClassicalGame上行TCP dir=out action=block protocol=tcp localport=32102");
		system("netsh advfirewall firewall add rule name=OriginDispath上行TCP dir=out action=block protocol=tcp localport=36000");
		system("netsh advfirewall firewall add rule name=OriginGame上行TCP dir=out action=block protocol=tcp localport=36102");
		system("netsh advfirewall firewall add rule name=OriginGanDispath上行TCP dir=out action=block protocol=tcp localport=36100");
		system("netsh advfirewall firewall add rule name=OriginGanGame上行TCP dir=out action=block protocol=tcp localport=36101");
		/*添加上行UDP规则*/
		system("netsh advfirewall firewall add rule name=ClassicalDispath上行UDP dir=out action=block protocol=udp localport=32443");
		system("netsh advfirewall firewall add rule name=ClassicalGame上行UDP dir=out action=block protocol=udp localport=32102");
		system("netsh advfirewall firewall add rule name=OriginDispath上行UDP dir=out action=block protocol=udp localport=36000");
		system("netsh advfirewall firewall add rule name=OriginGame上行UDP dir=out action=block protocol=udp localport=36102");
		system("netsh advfirewall firewall add rule name=OriginGanDispath上行UDP dir=out action=block protocol=udp localport=36100");
		system("netsh advfirewall firewall add rule name=OriginGanGame上行UDP dir=out action=block protocol=udp localport=36101");
		/*添加下行TCP规则*/
		system("netsh advfirewall firewall add rule name=ClassicalDispath上行TCP dir=in action=block protocol=tcp localport=32443");
		system("netsh advfirewall firewall add rule name=ClassicalGame上行TCP dir=in action=block protocol=tcp localport=32102");
		system("netsh advfirewall firewall add rule name=OriginDispath上行TCP dir=in action=block protocol=tcp localport=36000");
		system("netsh advfirewall firewall add rule name=OriginGame上行TCP dir=in action=block protocol=tcp localport=36102");
		system("netsh advfirewall firewall add rule name=OriginGanDispath上行TCP dir=in action=block protocol=tcp localport=36100");
		system("netsh advfirewall firewall add rule name=OriginGanGame上行TCP dir=in action=block protocol=tcp localport=36101");
		/*添加下行UDP规则*/
		system("netsh advfirewall firewall add rule name=ClassicalDispath上行UDP dir=in action=block protocol=udp localport=32443");
		system("netsh advfirewall firewall add rule name=ClassicalGame上行UDP dir=in action=block protocol=udp localport=32102");
		system("netsh advfirewall firewall add rule name=OriginDispath上行UDP dir=in action=block protocol=udp localport=36000");
		system("netsh advfirewall firewall add rule name=OriginGame上行UDP dir=in action=block protocol=udp localport=36102");
		system("netsh advfirewall firewall add rule name=OriginGanDispath上行UDP dir=in action=block protocol=udp localport=36100");
		system("netsh advfirewall firewall add rule name=OriginGanGame上行UDP dir=in action=block protocol=udp localport=36101");
		cout << "防火墙规则关闭完毕，" << endl;
		break;
	}
	return 0;
}


int Emergency()
{
	cout << "\n正在执行应急关服程序..." << endl;
	FireWallSet(false);
	StopServerImmiately();
	StopDataBase();
	cout << "\n请问是否关机?(y/n):" << endl;
	char UserIntPut;
	cin >> UserIntPut;
	swer:
	switch (UserIntPut)
	{
	case 'y':
		system("shutdown /s");
		MessageBox(NULL, "已经发送关机请求，可以调起CMD，/a去取消此次关机，最后还祝没有任何事情发生...", "See You Next Time！", MB_OK | MB_ICONINFORMATION);
		exit(0);
		break;
	case 'n':
		return 0;
		break;
	default:
		cout << "\n请问是否关机?(y/n):" << endl;
		cin >> UserIntPut;
		goto swer;
		break;
	}
}

int DelDataBase()
{
	system("cls");
	cout << "你个BYD的玩意真的TMD要删库跑路？(y/n)" << endl;
	char UserIntPut;
	cin >> UserIntPut;
swer:
	switch (UserIntPut)
	{
	case 'y':
		MessageBox(NULL, "CNM，SB，模块在开发，傻了吧，哈哈哈\n 滚", "SB!!!", MB_OK | MB_ICONERROR);
		exit(0);
		break;
	case 'n':
		MessageBox(NULL, "你TM好歹还是个人", "6", MB_OK | MB_ICONINFORMATION);
		return 0;
		break;
	default:
		cout << "你个BYD的玩意真的TMD要删库跑路？(y/n)" << endl;
		cin >> UserIntPut;
		goto swer;
		break;
	}

	return 0;
}
